package xcmg.device.web.agentReturn;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xcmg.device.infra.BasicController;
import xcmg.device.infra.ErrorCode;
import xcmg.device.service.agentReturn.AgentReturnDetailService;
import xcmg.device.service.vo.FunctionResult;
import xcmg.device.service.vo.agentReturn.AgentReturnShowVO;
import yb.ecp.fast.infra.annotation.FastMappingInfo;
import yb.ecp.fast.infra.infra.ActionResult;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: xiali@bkrwin.com
 * @description:
 * @date： 2019/6/20 20:23
 **/
@RestController
@RequestMapping("/agentReturnDetail")
public class AgentReturnDetailController  extends BasicController {
    @Autowired
    AgentReturnDetailService agentReturnDetailService;

    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ApiOperation(value = "供应商退货详情")
    @FastMappingInfo(needLogin = true)
    public ActionResult list(@RequestParam String returnId) throws Exception {
        if (null==returnId){
            return actionResult(ErrorCode.IllegalArument);
        }
        FunctionResult result=agentReturnDetailService.list(returnId);
        return actionResult(result.getCode(),result.getValue());
    }

    @GetMapping(value = "/item")
    @ApiOperation(value = "获取详情列表")
    @FastMappingInfo(needLogin = true)
    public ActionResult item(String[]  returnIds) throws Exception {
        if (null == returnIds){
            return actionResult(ErrorCode.IllegalArument);
        }
        List<AgentReturnShowVO> voList = new ArrayList<>();
        for (String id : returnIds
                ) {
            AgentReturnShowVO item = agentReturnDetailService.item(id);
            voList.add(item);
        }
        return actionValueResult(voList);
    }

}
